<template>
  <el-dialog :visible.sync="visible" title="调整课表" :close-on-click-modal="false" width="400px">
    <el-form ref="changeScheduleForm" :rules="rules" :model="changeScheduleInfo" class="demo-form-inline" label-width="100px">
      <el-form-item label="调整时间" prop="target">
        <el-date-picker
          v-model="changeScheduleInfo.target"
          :picker-options="pickerOptions"
          type="datetime"
          format="yyyy-MM-dd HH:mm"
          placeholder="选择日期时间"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click.native="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click.native="changeSchedule">提交</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { changeScheduleReq } from '@/api/schedule'
export default {
  data() {
    return {
      visible: false,
      loading: false,
      scheduleId: 0,
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now(0 - 8.64e7)
        }
      },
      changeScheduleInfo: {
        scheduleId: 0,
        target: ''
      },
      rules: {
        target: [
          { required: true, message: '请选择调整的日期和时间', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    cancel() {
      this.visible = false
    },
    async changeSchedule() {
      this.$refs.changeScheduleForm.validate((valid) => {
        if (valid) {
          this.changeScheduleInfo.scheduleId = this.scheduleId
          changeScheduleReq(this.changeScheduleInfo).then(res => {
            // 成功回调
            this.$emit('scheduleChanged', 1)
            this.visible = false
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped>

</style>